import React, { Component, Suspense, lazy } from "react";
import {
  Route,
  Switch,
  Redirect,
  HashRouter as Router,
} from "react-router-dom";
import { Spin } from "antd";

const Home = lazy(() =>
  import(/* webpackChunkName: "Home" */ "../pages/Home/index.js")
);

const Ques = lazy(() =>
  import(/* webpackChunkName: "Ques" */ "../pages/Ques/index.js")
);

const System = lazy(() =>
  import(/* webpackChunkName: "System" */ "../pages/System/index.js")
);

function Routes(props) {
  return (
    <Suspense
      fallback={
        <div style={{ paddingTop: "50%", textAlign: "center" }}>
          <Spin tip="加载中..." />
        </div>
      }
    >
      <Switch>
        <Route path={`/home`} component={Home} />
        <Route path={`/ques`} component={Ques} />
        <Route path={`/system`} component={System} />
        <Redirect
          to={{
            pathname: `/home`,
          }}
        />
      </Switch>
    </Suspense>
  );
}

export default Routes;
